﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using NDeployer.Common;
using System.Windows;
using System.Windows.Controls;
using NDeployer.Studio.Views;
using NDeployer.Model;

namespace NDeployer.Studio.ViewModels
{
    public class TaskWorkflowViewModel : ViewModelBase
    {
        static int counter = 1;
        public TaskWorkflowViewModel()
        {
            //Name = "Task Workflow " + counter++;
        }
       
        private ICommand doDropCommand;
        public ICommand DoDropCommand
        {
            get
            {
                if (doDropCommand == null)
                {
                    doDropCommand = new DelegateCommand(DoDrop);
                }
                return doDropCommand;
            }
        }




        public void DoDrop(object parameter)
        {
            var composite = parameter as CompositeCommandParameter;
            var sender = composite.Sender;
            var e = composite.Parameter as DragEventArgs;
            var DropCanvas = sender as Canvas;
            var draggedItem = (TaskMetadata)e.Data.GetData("ElementToDrag");
            Point position = e.GetPosition(DropCanvas);

            var element = new TaskView() { };
            var dc = element.DataContext as TaskViewModel;
            dc.Task = draggedItem;

            Canvas.SetLeft(element, position.X);
            Canvas.SetTop(element, position.Y);
            DropCanvas.Children.Add(element);
        }
    }
}
